#include<bits/stdc++.h>
using namespace std;

int T;
const int N = 10010;
int n[N],m[N],L[N],V[N];
int d[N][N],v[N][N],a[N][N],p[N][N];
int ans1[N],ans2[N];

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> T;
    for(int i = 1;i <= T;i ++)
    {
        cin >> n[i] >> m[i] >> L[i] >> V[i];
        for(int j = 1;j <= n[i];j ++) cin >> d[i][j] >> v[i][j] >> a[i][j];
        for(int j = 1;j <= m[i];j ++) cin >> p[i][j];
    }
    for(int i = 1;i <= T;i ++)
    {
        for(int j = 1;j <= n[i];j ++)
        {
            if(v[i][j] > V[i]) ans1[i] ++;
            else ans2[i] ++;
        }
    }
    for(int i = 1;i <= T;i ++) cout << ans1[i] << " " << ans2[i] << "\n";
    return 0;
}
